package com.hRpc;

import com.hrpc.utils.zookeeper.ZookeeperNode;
import com.hrpc.utils.zookeeper.ZookeeperUtil;
import org.apache.zookeeper.*;

import java.io.IOException;
import java.util.List;

/**
 * zookeeper注册中心的管理页面
 */
public class Application {
    public static void main(String[] args) {
            //创建一个zookeeper实例
            ZooKeeper zooKeeper= ZookeeperUtil.createZookeeper();
            String basePath = "/hRpc-metadata";
            String serverPath = basePath+"/servers";
            String clientPath = basePath+"/clients";

            ZookeeperNode baseNode=new ZookeeperNode(basePath,null);
            ZookeeperNode serverNode=new ZookeeperNode(serverPath,null);
            ZookeeperNode clientNode=new ZookeeperNode(clientPath,null);
            //创建节点
            List.of(baseNode,serverNode,clientNode).forEach(zookeeperNode ->{
                        ZookeeperUtil.createNode(zooKeeper,zookeeperNode,null,CreateMode.PERSISTENT);
                }
            );
            //关闭zookeeper连接
            ZookeeperUtil.close(zooKeeper);

    }
}
